#!/bin/sh

if [ $# -lt 1 ]; then
	echo "$0 server [user] [port]"
	exit 0
fi

desktop_file=~/.local/share/applications/gnome-terminal.desktop

if [ ! -f $desktop_file ]; then
	cp /usr/share/applications/gnome-terminal.desktop $desktop_file
	unity --reset #--reset-icons
fi


add()
{
	server=$1
	user=$2
	port=$3

	cmd="ssh $server"
	[ -n "$user" ] && cmd="$cmd -l$user"
	[ -n "$port" ] && cmd="$cmd -p$port"

	# keep action unique
	action="ssh`date +%s`"

	name="$server"
	[ -n "$user" ] && name="$user@$name"

	sed -i "s/^Actions=.*/&;$action/" $desktop_file
	
	cat >> $desktop_file << EOF
[Desktop Action $action]
Name=$name
Exec=gnome-terminal -e "$cmd"
OnlyShowIn=Unity

EOF
}


add $1 $2 $3



